#!/usr/bin/env python
# -*- coding: utf8 -*-

from qtpy import QtWidgets, QtCore, QtWidgets

class FramelessMovableWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(FramelessMovableWidget, self).__init__(parent)

        # 初始化参数
        self._move = False
        self._parent = parent

        # 无边框透明
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowSystemMenuHint)
        # self.setAttribute(Qt.WA_TranslucentBackground)
        self.setWindowOpacity(0)
        self.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed)
        self.maxNormal=False

    def mousePressEvent(self,event):
        if event.button() == QtCore.Qt.LeftButton:
            self._move = True
            self._src_pos = event.globalPos()
            self._parent_pos = self._parent.pos()
            
    def mouseReleaseEvent(self, event):
        self._move = False

    def mouseMoveEvent(self,event):
        if self._move:
            offset = event.globalPos() - self._src_pos
            self._parent.move( self._parent_pos + offset)